package com.suning.sawp.loadtest;

import com.google.common.collect.AbstractIterator;

public class MockStaffGenerator extends AbstractIterator<com.suning.sawp.loadtest.MockStaffGenerator.Staff> {

    public static class Staff {
        private String staffId;

        private String storeCode;

        private String disCode;

        public Staff() {

        }

        public Staff(String disCode, String storeCode, String staffId) {
            this.storeCode = storeCode;
            this.staffId = staffId;
            this.disCode = disCode;

        }

        public String getDisCode() {
            return disCode;
        }

        public void setDisCode(String disCode) {
            this.disCode = disCode;
        }

        public String getStaffId() {
            return staffId;
        }

        public void setStaffId(String staffId) {
            this.staffId = staffId;
        }

        public String getStoreCode() {
            return storeCode;
        }

        public void setStoreCode(String storeCode) {
            this.storeCode = storeCode;
        }
    }

    int storeCode = 0;
    long staffId = 0;
    long disCode = 0;
    final long maxI;
    final long maxJ;
    final long maxK;
    long i = 0;
    long j = 0;
    long k = 0;
    boolean end;
    boolean infinite;

    Staff staff;

    /**
     * 
     * @param maxI 每门店员工数
     * @param maxJ 每大区门店数
     * @param maxK 大区数
     * @param infinite
     */
    public MockStaffGenerator(long maxI, long maxJ, long maxK, boolean infinite) {
        this.maxI = maxI;
        this.maxJ = maxJ;
        this.maxK = maxK;
        this.infinite = infinite;
    }

    /**
     * 是否结束
     * 
     * @return
     */
    private boolean add() {
        staff = new Staff(Long.toString(disCode + Long.parseLong("Z0000", 36), 36).toUpperCase(),
                Long.toString(storeCode + Long.parseLong("Z000", 36), 36).toUpperCase(),
                Long.toString(staffId + Long.parseLong("Z0000000", 36), 36).toUpperCase());
        staffId++;
        if (++i >= maxI) {
            i = 0;
            storeCode++;
            if (++j >= maxJ) {
                j = 0;
                disCode++;
                if (++k >= maxK) {
                    k = 0;
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    protected Staff computeNext() {
        if (end) {
            return endOfData();
        }
        end = add() && !infinite;
        return staff;
    }

}
